package com.wc.alorithm_blue_bridge._字符串.KMP.Q3178;

import java.util.*;

/**
 * @Author congege
 * 你也喜欢幸运字符串吗？
 * https://www.lanqiao.cn/problems/3178/learning/?page=1&first_category_id=1
 * @Date Created in 2023/12/1-16:07
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        String s = scan.nextLine();
        int[] next = new int[n + 1];
        // dp[i] 表示 0 到 i-1的前缀字符串出现的次数
        long[] dp = new long[n + 1];
        Arrays.fill(dp, 1);
        next[0] = -1;
        next[1] = 0;
        int i = 2, k;
        while (i <= n) {
            k = next[i - 1];
            while (k != -1 && s.charAt(i - 1) != s.charAt(k)) {
                k = next[k];
            }
            next[i] = k + 1;
            i++;
        }
        for (i = n; i >= 1; i--) {
            dp[next[i]] += dp[i];
        }
        long ans = 0;
        for (i = 1; i <= n; i++) {
            ans += dp[i];
        }
        System.out.println(ans);
    }
}
